<template>
  <div>
    <el-row>
      <el-col :span="24">
        <div class="search-box">
          <el-form :inline="true" size="medium">
          </el-form>

          <el-form :inline="true" size="medium" :model="searchForm">
            <el-form-item>
              <el-button type="primary" @click="search">刷新</el-button>
            </el-form-item>
          </el-form>
        </div>
      </el-col>
    </el-row>

    <el-table
      :data="tableData"
      :header-cell-style="{backgroundColor:'#f4f4f5',textAlign:'center'}"
      :cell-style="{textAlign:'center'}"
      :height="tableHeight"
      border
      style="width: 100%">
      <el-table-column
        prop="id"
        label="序号"
        type="index"
        width="80">
      </el-table-column>
      <el-table-column
        prop="carEntName"
        label="车企"
        min-width="120">
      </el-table-column>
      <el-table-column
        prop="carName"
        label="车辆"
        min-width="120">
      </el-table-column>
      <el-table-column
        prop="carTypeName"
        label="车型类别"
        min-width="100">
      </el-table-column>
      <el-table-column
        prop="productTypeName"
        label="申报类型"
        min-width="150">
        <template scope="scope">
          {{scope.row.productTypeName+"/"+scope.row.parentProductTypeName}}
          <template v-if="scope.row.hasDx">+定型</template>
        </template>
      </el-table-column>
      <el-table-column
        prop="groupName"
        label="打包项目"
        min-width="120">
      </el-table-column>
      <el-table-column
        prop="testItems"
        label="检测项目"
        min-width="170">
        <template scope="scope">
          <span v-html="parseTestItem2(scope.row)"></span>
        </template>
      </el-table-column>
      <el-table-column
        prop="price"
        label="折前价"
        min-width="120">
      </el-table-column>
      <el-table-column
        prop="rebate"
        label="折扣"
        min-width="120">
        <template scope="scope">
          {{scope.row.rebate}}%
        </template>
      </el-table-column>
      <el-table-column
        prop="payPrice"
        label="折后价"
        min-width="120">
      </el-table-column>
      <el-table-column
        prop="isSend"
        label="是否送样"
        min-width="100">
        <template scope="scope">
          {{scope.row.isSend?"是":"否"}}
        </template>
      </el-table-column>
      <el-table-column
        prop="siteName"
        label="场地"
        min-width="120">
      </el-table-column>
      <el-table-column
        prop="orgName"
        label="检测机构"
        min-width="120">
      </el-table-column>

      <el-table-column
        prop="id"
        label="任务状态"
        min-width="120">
        <template scope="scope">
          <span v-if="scope.row.stepStatus == 3">回退(原因:{{scope.row.msg}})</span>
          <span v-if="scope.row.stepStatus == 4">转交</span>
        </template>
      </el-table-column>
      <!--
      <el-table-column
        prop="userName1"
        label="工程师A"
        min-width="120">
      </el-table-column>
      <el-table-column
        prop="userName2"
        label="工程师B"
        min-width="120">
      </el-table-column>
      <el-table-column
        prop="userName3"
        label="工程师C"
        min-width="120">
      </el-table-column>
      -->
      <el-table-column
        prop="updateTime"
        label="最后修改时间"
        min-width="160">
        <template scope="scope">
          {{fmtDate(scope.row.updateTime)}}
        </template>
      </el-table-column>
      <el-table-column
        prop="note"
        label="备注"
        min-width="160">
      </el-table-column>
      <el-table-column
        fixed="right"
        prop="address"
        label="操作"
        min-width="150">
        <template slot-scope="scope">
          <div v-if="scope.row.step == 2">
            <el-button size="mini" type="primary" @click="handleStep2(scope.$index, scope.row)">处理</el-button>
          </div>
          <div v-if="scope.row.step == 3">
            <el-button size="mini" type="primary" @click="handleStep3(scope.$index, scope.row)">处理</el-button>
            <el-button size="mini" type="primary" @click="handleBack(scope.$index, scope.row)">回退</el-button>
          </div>
          <div v-if="scope.row.step == 4">
            <el-button size="mini" type="primary" @click="handleStep4(scope.$index, scope.row)">处理</el-button>
            <el-button size="mini" type="primary" @click="handleBack(scope.$index, scope.row)">回退</el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <div class="block">
       <span class="demonstration"></span>
       <el-pagination
         @size-change="handleSizeChange"
         @current-change="handleCurrentChange"
         :current-page="currentPage"
         :page-sizes="[10, 20, 50, 100,200]"
         :page-size="pageSize"
         layout="total, sizes, prev, pager, next, jumper"
         :total="total">
       </el-pagination>
     </div>

    <el-dialog title="拟定需求" :visible.sync="step2EditFormVisible" width="500px" :close-on-click-modal="false">
      <el-form :model="editForm" ref="step2EditForm">
        <template v-for="item in editForm.dataList">
          <el-form-item :label="getEditFormLabel(item.type)+'需求'" label-width="120px">
            <el-input v-model="item.need" autocomplete="off"></el-input>
          </el-form-item>
        </template>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="step2EditFormVisible = false">取 消</el-button>
        <el-button type="primary" @click.native.prevent="submitForm">暂存</el-button>
        <el-button type="success" @click.native.prevent="submitFormNext">下一步</el-button>
      </div>
    </el-dialog>

    <el-dialog title="填写" :visible.sync="step3EditFormVisible" width="700px" :close-on-click-modal="false">
      <el-form :model="editForm" ref="step3EditForm">
        <template v-for="item in editForm.dataList">
          <el-form-item :label="getEditFormLabel(item.type)" label-width="120px" v-if="item.type==1">
            <div style="color: #999;font-size: 12px;">需求：{{item.need}}</div>
            <el-input v-model="item.content" autocomplete="off"></el-input>
          </el-form-item>

          <el-form-item :label="getEditFormLabel(item.type)" label-width="120px" v-if="item.type==2">
            <div style="color: #999;font-size: 12px;">需求：{{item.need}}</div>
            <el-upload
              class="upload-demo"
              name="file"
              :action="uploadActionUrl"
              :on-preview="handlePreview"
              :on-success="handleAvatarSuccess"
              :before-upload="beforeAvatarUpload2"
              :on-error="handleAvatarError"
              accept=".png,.jpeg,.jpg"
              multiple
              :file-list="fileList2">
              <el-button size="small" type="primary">点击上传</el-button>
              <div slot="tip" class="el-upload__tip">只能上传jpg/jpeg/png文件</div>
            </el-upload>
          </el-form-item>
          <el-form-item :label="getEditFormLabel(item.type)" label-width="120px" v-if="item.type==3">
            <div style="color: #999;font-size: 12px;">需求：{{item.need}}</div>
            <el-upload
              class="upload-demo"
              name="file"
              :action="uploadActionUrl"
              :on-preview="handlePreview"
              :on-success="handleAvatarSuccess"
              :before-upload="beforeAvatarUpload3"
              :on-error="handleAvatarError"
              accept=".avi,.mp4"
              multiple
              :file-list="fileList3">
              <el-button size="small" type="primary">点击上传</el-button>
              <div slot="tip" class="el-upload__tip">只能上传avi/mp4文件</div>
            </el-upload>
          </el-form-item>
          <el-form-item :label="getEditFormLabel(item.type)" label-width="120px" v-if="item.type==4">
            <div style="color: #999;font-size: 12px;">需求：{{item.need}}</div>
            <el-upload
              class="upload-demo"
              name="file"
              :action="uploadActionUrl"
              :on-preview="handlePreview"
              :on-success="handleAvatarSuccess"
              :before-upload="beforeAvatarUpload4"
              :on-error="handleAvatarError"
              accept=".png,.jpeg,.jpg"
              multiple
              :file-list="fileList4">
              <el-button size="small" type="primary">点击上传</el-button>
              <div slot="tip" class="el-upload__tip">只能上传jpg/jpeg/png文件</div>
            </el-upload>
          </el-form-item>
          <el-form-item :label="getEditFormLabel(item.type)" label-width="120px" v-if="item.type==5">
            <div style="color: #999;font-size: 12px;">需求：{{item.need}}</div>
            <el-upload
              class="upload-demo"
              name="file"
              :action="uploadActionUrl"
              :on-preview="handlePreview"
              :on-success="handleAvatarSuccess"
              :before-upload="beforeAvatarUpload5"
              :on-error="handleAvatarError"
              accept=".png,.jpeg,.jpg"
              multiple
              :file-list="fileList5">
              <el-button size="small" type="primary">点击上传</el-button>
              <div slot="tip" class="el-upload__tip">只能上传jpg/jpeg/png文件</div>
            </el-upload>
          </el-form-item>

        </template>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="step3EditFormVisible = false">取 消</el-button>
        <el-button type="primary" @click.native.prevent="submitForm">暂存</el-button>
        <el-button type="success" @click.native.prevent="submitFormNext">下一步</el-button>
      </div>
    </el-dialog>

    <el-dialog title="完成" :visible.sync="step4EditFormVisible" width="700px" :close-on-click-modal="false">
      <el-form :model="editForm" ref="step4EditForm">
        <template v-for="item in editForm.dataList">
          <el-form-item :label="getEditFormLabel(item.type)" label-width="120px" v-if="item.type==1">
            <div style="color: #999;font-size: 12px;">需求：{{item.need}}</div>
            <div style="color: #666;font-size: 12px;">{{item.content}}</div>
          </el-form-item>

          <el-form-item :label="getEditFormLabel(item.type)" label-width="120px" v-if="item.type==2">
            <div style="color: #999;font-size: 12px;">需求：{{item.need}}</div>
            <div style="color: #666;font-size: 12px;vertical-align: middle;">
              <span style="vertical-align: middle;"></span>
              <el-image v-for="(item,index) in fileList2"
                style="width: 100px; height: 100px;cursor: pointer;"
                :src="fileBaseUrl+item.name"
                @click="handlePreview({url: fileBaseUrl+item.name})">
              </el-image>
            </div>
          </el-form-item>
          <el-form-item :label="getEditFormLabel(item.type)" label-width="120px" v-if="item.type==3">
            <div style="color: #999;font-size: 12px;">需求：{{item.need}}</div>
            <div style="color: #666;font-size: 12px;vertical-align: middle;">
              <div v-for="(item,index) in fileList3"
                style="cursor: pointer;"
                @click="handlePreview({url: fileBaseUrl+item.name})">
                {{item.name}}
              </div>
            </div>
          </el-form-item>
          <el-form-item :label="getEditFormLabel(item.type)" label-width="120px" v-if="item.type==4">
            <div style="color: #999;font-size: 12px;">需求：{{item.need}}</div>
            <div style="color: #666;font-size: 12px;vertical-align: middle;">
              <span style="vertical-align: middle;"></span>
              <el-image v-for="(item,index) in fileList4"
                style="width: 100px; height: 100px;cursor: pointer;"
                :src="fileBaseUrl+item.name"
                @click="handlePreview({url: fileBaseUrl+item.name})">
              </el-image>
            </div>
          </el-form-item>
          <el-form-item :label="getEditFormLabel(item.type)" label-width="120px" v-if="item.type==5">
            <div style="color: #999;font-size: 12px;">需求：{{item.need}}</div>
            <div style="color: #666;font-size: 12px;vertical-align: middle;">
              <span style="vertical-align: middle;"></span>
              <el-image v-for="(item,index) in fileList5"
                style="width: 100px; height: 100px;cursor: pointer;"
                :src="fileBaseUrl+item.name"
                @click="handlePreview({url: fileBaseUrl+item.name})">
              </el-image>
            </div>
          </el-form-item>

        </template>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="step4EditFormVisible = false">取 消</el-button>
        <!-- <el-button type="primary" @click.native.prevent="submitForm">暂存</el-button> -->
        <el-button type="success" @click.native.prevent="submitFormNext">完成</el-button>
      </div>
    </el-dialog>

    <!-- 图片预览 -->
    <el-dialog :visible.sync="imgDialogVisible" width="650px" @close="handlePreviewClose">

      <video width="600px" :src="dialogImageUrl" alt="" controls="controls" v-if="isVideo(dialogImageUrl)">
        您的浏览器无法播放视频
      </video>
      <img width="600px" :src="dialogImageUrl" alt="" v-else="!isVideo(dialogImageUrl)">

    </el-dialog>

    <el-dialog title="回退" :visible.sync="backFormVisible" width="500px" :close-on-click-modal="false">
      <el-form :model="backForm" ref="backForm">
          <el-form-item label="回退步数" label-width="120px">
            <el-select v-model="backForm.step" placeholder="请选择">
            <template v-if="backForm.currentStep == 3">
              <el-option key="2" label="回退一步" value="2"></el-option>
            </template>
            <template v-if="backForm.currentStep == 4">
              <el-option key="2" label="回退两步" value="2"></el-option>
              <el-option key="3" label="回退一步" value="3"></el-option>
            </template>
          </el-select>
          </el-form-item>
          <el-form-item label="原因" label-width="120px">
            <el-input v-model="backForm.msg" autocomplete="off"></el-input>
          </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="backFormVisible = false">取 消</el-button>
        <!-- <el-button type="primary" @click.native.prevent="submitForm">暂存</el-button> -->
        <el-button type="primary" @click.native.prevent="submitBackForm">回退</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {validPhone} from '@/common/utils/validate.js'
import request from '@/common/utils/request.js'
import util from '../../../common/utils/util.js'
import {getToken} from '../../../common/utils/auth.js'
import {getTestOrderTaskList, taskSaveOrNext, taskBack} from "../../../api/test_order.js";
import {getAllTestCarEnterpriseList} from "../../../api/test_car_enterprise.js"
import {getTestCarListByEntId} from "../../../api/test_car.js"
import {getAllCarTypeList} from '../../../api/car_type.js'
import {getAllTestProductTypeList} from '../../../api/test_product_type.js'
import {getAllTestGroupListByParam} from '../../../api/test_group.js'
import {getAllTestSiteList} from '../../../api/test_site.js'
import {getAllUserList} from '../../../api/user.js'
import {getAllTestOrgList} from '../../../api/test_org.js'

export default {
  name: "taskOrderManage",
  data() {
    return {
      total: 0,
      pageSize: 10,
      currentPage: 1,
      tableData: [],
      tableHeight: 200,

      step2EditFormVisible:false,
      step3EditFormVisible:false,
      step4EditFormVisible:false,
      editForm: {
        id: 0,
        dataList: [],
        next: 0,
      },
      step2EditRules: {
        // xxx: [{ required: true, message:"请选择车企", trigger: 'blur'}],
      },
      loadingDiv: null,
      searchForm: {
        stepList: [],
        step:''
      },

      hasDxDisabled:true,
      nextShow: false,
      fileList2:[],
      fileList3:[],
      fileList4:[],
      fileList5:[],
      uploadActionUrl:'',
      uploadKey:'',
      fileBaseUrl:'',
      dialogImageUrl:'',
      imgDialogVisible: false,

      backFormVisible:false,
      backForm:{
        id:'',
        msg:'',
        step:'',
        currentStep:'',
      },
    }
  },
  watch:{
    $route (to, from ) {
      // 监听路由变化, 实现类似 小程序的 onShow 事件
      if (to.path === '/task/test_order_manage') {
        if(this.nextShow){

        }
      }
    },

  },
  created() {
    let step=this.$route.params.step;
    if(step == 2){
      this.searchForm.stepList=[2];
      this.searchForm.step = 2;
    }else if(step == 3){
      this.searchForm.stepList=[3];
      this.searchForm.step = 3;
    }else if(step == 4){
      this.searchForm.stepList=[4];
      this.searchForm.step = 4;
    }
  },
  mounted() {
    this.init();
    this.getDataList(this.currentPage);

    this.$nextTick(() => {
        this.tableHeight = document.documentElement.clientHeight - 198;
    })
    window.onresize = () => {
      this.$nextTick(() => {
          this.tableHeight = document.documentElement.clientHeight - 198;
      })
    }

    let t = getToken();
    this.uploadActionUrl = this.$adminApiUrl + "/file/upload?_t="+t;
    this.fileBaseUrl = this.$adminApiUrl+"/file/get?_t="+t+"&f=";
  },
  methods: {
    handleBack(index, row){
      this.backForm.id=row.id;
      this.backForm.msg = row.msg;
      this.backForm.currentStep=row.step;
      this.backFormVisible=true;
    },

    submitBackForm(){
      if(util.isEmpty(this.backForm.step)){
        this.$message({
          message: "请选择回退步数",
          type: 'warning'
        });
        return;
      }
      if(util.isEmpty(this.backForm.msg)){
        this.$message({
          message: "请填写回退原因",
          type: 'warning'
        });
        return;
      }

      let loadingDiv = util.showLoading("回退中...");
      taskBack(this.backForm).then(res => {
        loadingDiv.close();
        if(res.code == 0) {
          this.$alert(res.msg, "回退失败", {dangerouslyUseHTMLString:true,type:'warning'})
        }else if(res.code == 1) {
          this.$alert(res.msg, "回退成功", {dangerouslyUseHTMLString:true,type:'success'})
            .then(res=>{
              this.backFormVisible=false;
              this.getDataList(this.currentPage);

            })
        }
      }).catch(res=>{
        if (loadingDiv){
          loadingDiv.close();
        }
      })
    },

    isVideo(val){
      if(util.isEmpty(val)){
        return false;
      }
      if(val.toLowerCase().indexOf(".avi") != -1 || val.toLowerCase().indexOf(".mp4") != -1){
        return true;
      }
      return false;
    },
    isEmpty(val){
      return util.isEmpty(val);
    },
    handlePreviewClose(){
      this.dialogImageUrl='';
    },
    handlePreview(file) {
      this.dialogImageUrl = file.url;
      this.imgDialogVisible = true;
    },
    beforeAvatarUpload2(){
      this.uploadKey=2;
      this.avatarUploadLoadingDiv = util.showLoading("上传中");
    },
    beforeAvatarUpload3(){
      this.uploadKey=3;
      this.avatarUploadLoadingDiv = util.showLoading("上传中");
    },
    beforeAvatarUpload4(){
      this.uploadKey=4;
      this.avatarUploadLoadingDiv = util.showLoading("上传中");
    },
    beforeAvatarUpload5(){
      this.uploadKey=5;
      this.avatarUploadLoadingDiv = util.showLoading("上传中");
    },
    handleAvatarSuccess(res, file, fileList){
      this.avatarUploadLoadingDiv.close();
      if (res.code == 1){
       // this.editForm[this.uploadKey] = res.data;
        console.log("++++++++++++++++++");
        console.log(this.uploadKey);
        console.log(res.data);
        console.log("++++++++++++++++++");
        if(this.uploadKey == 2){
          this.fileList2.push({name:res.data, url: this.fileBaseUrl + res.data})
        }else if(this.uploadKey == 3){
          this.fileList3.push({name:res.data, url: this.fileBaseUrl + res.data})
        }else if(this.uploadKey == 4){
          this.fileList4.push({name:res.data, url: this.fileBaseUrl + res.data})
        }else if(this.uploadKey == 5){
          this.fileList5.push({name:res.data, url: this.fileBaseUrl + res.data})
        }
        return;
      }else{
        this.$message({
          message: res.msg,
          type: 'warning'
        });
      }
    },
    handleAvatarError(){
      this.avatarUploadLoadingDiv.close();
      this.$message({
        message: "照片上传失败,请检查网络",
        type: 'warning'
      });
    },
    getEditFormLabel(type){
      switch(type){
        case 1:
          return "申报参数";
        case 2:
          return "照片";
        case 3:
          return "视频";
        case 4:
          return "图纸";
        case 5:
          return "检测报告";

      }
    },
    fmtDate(d2, fmt) { // yyyy-MM-dd hh:mm:ss
      if (util.isEmpty(d2) || d2 <= 0){
        return "";
      }
      return  util.fmtDate(new Date(d2), fmt);
    },
    parseTestItem2(row){
      let items = row.testItems;
      let str = "";
      for(let i in items){
        if(items[i].level == 2){
          str += items[i].serialNumber+"/"+items[i].itemName+"<br>";
        }else if(items[i].level == 3){
          str += items[i].serialNumber+"/"+items[i].parentItemName+"/"+items[i].itemName+"<br>";
        }
      }
      return str;
    },

    parseTestItem(item){
      if(item.level == 2){
        return item.serialNumber+"/"+item.itemName;
      }else if(item.level == 3){
        return item.serialNumber+"/"+item.parentItemName+"/"+item.itemName;
      }

    },

    init(){

    },
    handleStep2(index, row){
      this.editForm.id = row.id;
      this.editForm.step = 2;
      this.editForm.dataList = row.dataList;
      this.step2EditFormVisible=true;
    },
    handleStep3(index, row){
      this.editForm.id = row.id;
      this.editForm.step = 3;
      this.editForm.dataList = row.dataList;

      let data2 = this.getDataWithType(this.editForm.dataList, 2);
      this.fileList2 = [];
      if(!util.isEmpty(data2.content)){
        let arr = data2.content.split(";");
        for(let i in arr){
          if(!util.isEmpty(arr[i])){
            this.fileList2.push({name:arr[i], url: this.fileBaseUrl + arr[i]})
          }
        }
      }

      let data3 = this.getDataWithType(this.editForm.dataList, 3);
      this.fileList3 = [];
      if(!util.isEmpty(data3.content)){
        let arr = data3.content.split(";");
        for(let i in arr){
          if(!util.isEmpty(arr[i])){
            this.fileList3.push({name:arr[i], url: this.fileBaseUrl + arr[i]})
          }
        }
      }

      let data4 = this.getDataWithType(this.editForm.dataList, 4);
      this.fileList4 = [];
      if(!util.isEmpty(data4.content)){
        let arr = data4.content.split(";");
        for(let i in arr){
          if(!util.isEmpty(arr[i])){
            this.fileList4.push({name:arr[i], url: this.fileBaseUrl + arr[i]})
          }
        }
      }

      let data5 = this.getDataWithType(this.editForm.dataList, 5);
      this.fileList5 = [];
      if(!util.isEmpty(data5.content)){
        let arr = data5.content.split(";");
        for(let i in arr){
          if(!util.isEmpty(arr[i])){
            this.fileList5.push({name:arr[i], url: this.fileBaseUrl + arr[i]})
          }
        }
      }
      this.step3EditFormVisible=true;
    },

    handleStep4(index, row){
      this.editForm.id = row.id;
      this.editForm.step = 4;
      this.editForm.dataList = row.dataList;

      let data2 = this.getDataWithType(this.editForm.dataList, 2);
      this.fileList2 = [];
      if(!util.isEmpty(data2.content)){
        let arr = data2.content.split(";");
        for(let i in arr){
          if(!util.isEmpty(arr[i])){
            this.fileList2.push({name:arr[i], url: this.fileBaseUrl + arr[i]})
          }
        }
      }

      let data3 = this.getDataWithType(this.editForm.dataList, 3);
      this.fileList3 = [];
      if(!util.isEmpty(data3.content)){
        let arr = data3.content.split(";");
        for(let i in arr){
          if(!util.isEmpty(arr[i])){
            this.fileList3.push({name:arr[i], url: this.fileBaseUrl + arr[i]})
          }
        }
      }

      let data4 = this.getDataWithType(this.editForm.dataList, 4);
      this.fileList4 = [];
      if(!util.isEmpty(data4.content)){
        let arr = data4.content.split(";");
        for(let i in arr){
          if(!util.isEmpty(arr[i])){
            this.fileList4.push({name:arr[i], url: this.fileBaseUrl + arr[i]})
          }
        }
      }

      let data5 = this.getDataWithType(this.editForm.dataList, 5);
      this.fileList5 = [];
      if(!util.isEmpty(data5.content)){
        let arr = data5.content.split(";");
        for(let i in arr){
          if(!util.isEmpty(arr[i])){
            this.fileList5.push({name:arr[i], url: this.fileBaseUrl + arr[i]})
          }
        }
      }
      this.step4EditFormVisible=true;
    },

    submitForm() {
      this.editForm.next = 0;
      this.taskSaveOrNext();
    },
    submitFormNext() {
      this.editForm.next = 1;
      this.taskSaveOrNext();
    },

    getDataWithType(dataList, type){
      for(let i in dataList){
        if(dataList[i].type == type){
          return dataList[i];
        }
      }
    },

    taskSaveOrNext(){

      if(this.editForm.step==3){
        let data2 = this.getDataWithType(this.editForm.dataList, 2);
        let content = '';
        for(let i in this.fileList2){
          content+=this.fileList2[i].name+";";
        }
        data2.content = content;

        let data3 = this.getDataWithType(this.editForm.dataList, 3);
        content = '';
        for(let i in this.fileList3){
          content+=this.fileList3[i].name+";";
        }
        data3.content = content;

        let data4 = this.getDataWithType(this.editForm.dataList, 4);
        content = '';
        for(let i in this.fileList4){
          content+=this.fileList4[i].name+";";
        }
        data4.content = content;

        let data5 = this.getDataWithType(this.editForm.dataList, 5);
        content = '';
        for(let i in this.fileList5){
          content+=this.fileList5[i].name+";";
        }
        data5.content = content;
      }


      // this.$refs.editForm.validate(valid => {
        // if(valid) {
          this.loading = true;
          let loadingText = "暂存中...";
          if(this.editForm.next == 1){
            loadingText = "下一步中...";
            if(this.editForm.step==4){
              loadingText = "完成中...";
            }
          }
          const loadingDiv = util.showLoading(loadingText)
          taskSaveOrNext(this.editForm).then(res => {
            let title = "暂存"
            if(this.editForm.next == 1){
              title = "下一步"
              if(this.editForm.step==4){
                title = "完成"
              }
            }
            if(res.code == 0) {
              this.$alert(res.msg, title+"失败", {dangerouslyUseHTMLString:true,type:'warning'})
            }else if(res.code == 1) {
              this.$alert(res.msg, title+"成功", {dangerouslyUseHTMLString:true,type:'success'})
                .then(()=> {
                  this.editFormVisible=false;
                  this.getDataList(this.currentPage);
                  if(this.editForm.step==2){
                    this.step2EditFormVisible=false;
                  }else if(this.editForm.step==3){
                    this.step3EditFormVisible=false;
                  }else if(this.editForm.step==4){
                    this.step4EditFormVisible=false;
                  }
                })
            }
            this.loading = false;
            loadingDiv.close();
          }).catch(res => {
            this.loading = false;
            loadingDiv.close();
          })
        // }
      // });
    },

    handleDelete(index, row) {
      let loadingDiv;
      this.$confirm("是否确认删除?","删除确认").then(res=>{
        if(res='confirm'){
          loadingDiv = util.showLoading("删除中...")
          return deleteTestOrder({id: row.id})
        }
      }).then(res => {
        loadingDiv.close();
        if(res.code == 0) {
          this.$alert(res.msg, "删除失败", {dangerouslyUseHTMLString:true,type:'warning'})
        }else if(res.code == 1) {
          this.$alert(res.msg, "删除成功", {dangerouslyUseHTMLString:true,type:'success'})
            .then(res=>{
              this.editFormVisible=false;
              this.getDataList(this.currentPage);

            })
        }
      }).catch(res=>{
        if (loadingDiv){
          loadingDiv.close();
        }
      })
    },
    getDataList(pageNum){
      const loadingDiv = util.showLoading()

      getTestOrderTaskList({
        pageSize: this.pageSize,
        pageNum: pageNum,
        stepList: this.searchForm.stepList,
      }).then(res => {
        if(res.code == 0) {
          this.$message({
            showClose: true,
            message: res.msg,
            type: 'error'
          });
        }else if(res.code == 1) {
          let data = res.data;
          this.currentPage = pageNum;
          this.total = data.total;
          this.tableData = data.dataList;
        }
        loadingDiv.close();
      }).catch(res => {
        loadingDiv.close();
      })
    },
    search() {
      this.getDataList(this.currentPage)
    },
    handleSizeChange(pageSize) {
            this.pageSize = pageSize;
            this.getDataList(1)
          },
    handleCurrentChange(pageNum) {
            this.getDataList(pageNum);
          },
  }
}
</script>

<style scoped lang="scss">
  // @import "~@/common/styles/element-variables.scss";
  .search-box {
    background-color: #FFFFFF;
    min-height: 36px;
    line-height: 36px;
    padding-top: 2px;
    padding-bottom: 6px;
    .el-form-item {
      margin-bottom: 0px !important;
    }
    .el-form--inline {
      display: inline-block;
    }
  }
  .pagination-box {
    text-align: left;
    margin-top: 10px;
  }
  .test-item-table{
    width: 80%;
    border-collapse: collapse;

    th, td {
      width: 33.3%;
      text-align: center;
      border: 1px solid #CCC;
    }
  }
</style>
<style lang="scss">
  .el-dialog__header {

  }
  .el-dialog__body {
    padding-top: 10px;
    padding-bottom: 0px;
  }
  .el-dialog__footer {
    padding-top: 0px;
  }
</style>
